﻿Imports System.Windows.Forms
Imports MyPOSLibrary

Public Class MainWindow

    Private Sub MainWindow_Activated(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Activated
        Me.Height = Screen.PrimaryScreen.WorkingArea.Height
        Me.Width = Screen.PrimaryScreen.WorkingArea.Width
    End Sub

    Private Sub MainWindow_Loaded(ByVal sender As Object, ByVal e As System.Windows.RoutedEventArgs) Handles Me.Loaded
        Dim metro As New Metrolizer
        metro.DisplayTiles(MetroStackPanel)

        Dim path As String = My.Settings.SkinPath
        Dim newDictionary As New ResourceDictionary()
        newDictionary.Source = New Uri(path, UriKind.Relative)
        Me.Resources.MergedDictionaries.Clear()
        Me.Resources.MergedDictionaries.Add(newDictionary)
    End Sub

    Private Sub MainWindow_MouseDown(ByVal sender As Object, ByVal e As System.Windows.Input.MouseButtonEventArgs) Handles Me.MouseDown
        DragMove()
    End Sub

    Private Sub CloseButton_Click(ByVal sender As Object, ByVal e As System.Windows.RoutedEventArgs) Handles CloseButton.Click
        Me.Close()
    End Sub

    Private Sub MinimizeButton_Click(ByVal sender As Object, ByVal e As System.Windows.RoutedEventArgs) Handles MinimizeButton.Click
        Me.WindowState = Windows.WindowState.Minimized
    End Sub

    Private Sub MetroStackPanel_MouseLeftButtonDown(ByVal sender As Object, ByVal e As System.Windows.Input.MouseButtonEventArgs) Handles MetroStackPanel.MouseLeftButtonDown
        Dim txt As TextBlock = DirectCast(DirectCast(DirectCast(e.Source, MyPOSLibrary.Tile).Content, System.Windows.Controls.Grid).Children(1), System.Windows.Controls.TextBlock)
        If txt.Text.ToLower = "sales" Then
            Dim saleBillWindow As New SalesBillWindow
            saleBillWindow.ShowDialog()
        ElseIf txt.Text.ToLower = "purchase" Then
            Dim PurchaseWindow As New PurchaseWindow(FormsList.Purchase)
            PurchaseWindow.ShowDialog()
        ElseIf txt.Text.ToLower = "purchase order" Then
            Dim PurchaseOrderWindow As New PurchaseWindow(FormsList.PurchaseOrder)
            PurchaseOrderWindow.ShowDialog()
        ElseIf txt.Text.ToLower = "receipt" Then
            Dim ReceiptWindow As New PaymentReceiptWindow(FormsList.Receipt)
            ReceiptWindow.ShowDialog()
        ElseIf txt.Text.ToLower = "payment" Then
            Dim PaymentWindow As New PaymentReceiptWindow(FormsList.Payment)
            PaymentWindow.ShowDialog()
        Else
            Dim master As New MasterWindow
            Select Case txt.Text.ToLower
                Case "client list"
                    master.FormType = FormsList.ClientList
                Case "company info"
                    master.FormType = FormsList.CompanyInfo
                Case "financial year"
                    master.FormType = FormsList.FinancialYear
                Case "item list"
                    master.FormType = FormsList.ItemsList
                Case "ledgers"
                    master.FormType = FormsList.Ledgers
                Case "look-ups"
                    master.FormType = FormsList.Lookup
                Case "user profile"
                    master.FormType = FormsList.UserProfile
                Case "users list"
                    master.FormType = FormsList.UsersList
                Case "vendor list"
                    master.FormType = FormsList.VendorList
            End Select
            master.ShowDialog()
        End If
        e.Handled = True
    End Sub
End Class
